package com.zdd.ehe.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdd.ehe.entity.RolePermission;
import com.zdd.ehe.mapper.RolePermissionMapper;
import com.zdd.ehe.service.IRolePermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.hadoop.classification.InterfaceAudience;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZhuiZhu
 * @since 2023-03-13
 */
@Service
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements IRolePermissionService {
    @Resource
    private RolePermissionMapper rolePermissionMapper;

    /**
     * 分页查询角色权限
     * @param page
     * @return
     */
    @Override
    public Page<RolePermission> getAllUserRoleByPage (Page<RolePermission> page){
        Page<RolePermission> pagex = rolePermissionMapper.getAllRolePermissionByPage(page);
        return pagex;
    }


    //拼接字符串
    @Override
    public List<RolePermission> getAllByRoleName(String roleName) {
        String role_name = "%" + roleName + "%";
        return rolePermissionMapper.getAllByRoleName(role_name);
    }


    /**
     * 根据 id删除
     * @param id
     * @return
     */
    @Override
    public int deleteById(int id) {
        return rolePermissionMapper.deleteById(id);
    }

    @Override
    public int insert(RolePermission rolePermission) {
        return rolePermissionMapper.insert(rolePermission);
    }

    @Override
    public List<Integer> getPermissionIdByRoleId(int roleId) {
        return rolePermissionMapper.getPermissionIdByRoleId(roleId);
    }

}
